package com.helloandroid.activesitting.bc;

import com.helloandroid.activesitting.ApplicationObject;
import com.helloandroid.activesitting.bl.ILocationDataReceived;

import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;

public class GPSConnector implements LocationListener {
	private final LocationManager _locManager;
	private Location _location;
	private ILocationDataReceived _receiver;

	public GPSConnector(ILocationDataReceived receiver) {
		this._receiver = receiver;
		this._locManager = (LocationManager) ApplicationObject.ApplicationContext
				.getSystemService(Context.LOCATION_SERVICE);
		this._locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
				0, 0, this);
		this._location = this._locManager
				.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
	}

	/**
	 * Returns current location
	 * 
	 * @return Location
	 */
	public Location GetLocation() {
		return this._location;
	}

	/**
	 * Returns Latitude value
	 * 
	 * @return double
	 */
	public double GetLatitude() {
		return this._location.getLatitude();
	}

	/**
	 * Returns Longitude value
	 * 
	 * @return double
	 */
	public double GetLongitude() {
		return this._location.getLongitude();
	}

	@Override
	public void onLocationChanged(Location location) {
		this._receiver.SetCoords(location.getLatitude(), location.getLongitude());
		this._location = location;
	}

	@Override
	public void onProviderDisabled(String provider) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onProviderEnabled(String provider) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onStatusChanged(String provider, int status, Bundle extras) {
		// TODO Auto-generated method stub
		
	}
}
